package Practice08.test6;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class TestEmployee {
    public static void main(String[] args) throws RuntimeException {

        ObjectInputStream ois = null;
        ObjectOutputStream oos = null;
        EmployeeUtils employeeUtils = null;
        List<Employee> list = new ArrayList<>();

        try {
            ois = new ObjectInputStream(new FileInputStream("E:\\Employee.txt"));
            list = (List<Employee>) ois.readObject();
        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }

        try {
            oos = new ObjectOutputStream(new FileOutputStream("E:\\Employee.txt"));

            employeeUtils = new EmployeeUtils(list);

            employeeUtils.add(1,"zhangsan","moon",9000);
            employeeUtils.add(2,"lisi","sun",7000);
            System.out.println(employeeUtils);//增
            employeeUtils.deleteById(2);
            System.out.println(employeeUtils);//删
            employeeUtils.updateById(1,"lisi","jungle",8888);
            System.out.println(employeeUtils);//改
            System.out.println(employeeUtils.selectById(1));//查

            oos.writeObject(employeeUtils.getList());

        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            try {
//                if (ois != null) {
//                    ois.close();
//                }
                if (oos != null) {
                    oos.close();
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
